import { createWebHistory, createRouter } from 'vue-router'
/* Layout */
import Layout from '@/layout'
// import { Component } from 'vue'

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: 'Index',
    "meta": {
      title: "首页",
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/index'),
        name: 'Index',
        hidden:true,
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '',
    redirect: '/index',
    hidden: true
  },
]
export const dynamicRoutes = [
]

// 动态路由，基于用户权限动态去加载
export const allPagesRoutes = [
    
    {
      id: 200,
      path: '/productMgmt',
      name: 'productMgmt',
      component: Layout,
      meta: { title: '商品管理', icon: 'dashboard', affix: true },
      children: [
        {
          id: 20010,
          path: '/productMgmt/productTelemplate',
          component: () => import('@/views/productMgmt/productTelemplate'),
          name: 'ProductTelemplate',
          meta: { title: '商品模板',  affix: true },
        },
        {
          id: 20010,
          path: '/productMgmt/productTelemplate/add',
          component: () => import('@/views/productMgmt/productTelemplate/add'),
          name: 'ProductTelemplateAdd',
          hidden:true,
          meta: { title: '添加模板',  affix: true },
        },
        {
          id: 20011,
          path: '/productMgmt/product',
          component: () => import('@/views/productMgmt/product'),
          name: 'Product',
          meta: { title: '商城商品',  affix: true }
        },
        {
          id: 20011,
          path: '/productMgmt/product/add',
          component: () => import('@/views/productMgmt/product/add'),
          name: 'ProductAdd',
          hidden:true,
          meta: { title: '添加商品',  affix: true },
        },
        {
          id: 20012,
          path: '/productMgmt/productCategory',
          component: () => import('@/views/productMgmt/productCategory'),
          name: 'ProductCategory',
          meta: { title: '商城分类',  affix: true }
        },
        {
          id: 20013,
          path: '/productMgmt/stock',
          component: () => import('@/views/productMgmt/stock'),
          name: 'Stock',
          meta: { title: '库存管理',  affix: true }
        },
        {
          id: 20014,
          path: '/productMgmt/stockLog',
          component: () => import('@/views/productMgmt/stockLog'),
          name: 'StockLog',
          meta: { title: '库存日志',  affix: true }
        },
        
      ]
    },
    {
      id: 600,
      path: '/sourceCodeMgmt',
      name: 'SourceCodeMgmt',
      component: Layout,
      meta: { title: '溯源码管理', icon: 'dashboard', affix: true },
      children: [
        {
          id: 60010,
          path: '/sourceCodeMgmt/sourceCodeList',
          component: () => import('@/views/sourceCodeMgmt/index'),
          name: 'SourceCodeMgmtList',
          meta: { title: '溯源码列表',  affix: true },
        },
        {
          id: 60010,
          path: '/sourceCodeMgmt/add',
          component: () => import('@/views/sourceCodeMgmt/add'),
          name: 'SourceCodeMgmtAdd',
          hidden:true,
          meta: { title: '添加溯源码',  affix: true },
        },
      ]
    },
    {
      id: 300,
      path: '/orderMgmt',
      component: Layout,
      name: 'OrderMgmt',
      meta: { title: '订单管理', icon: 'dashboard', affix: true },
      children: [
        {
          id: 30010,
          path: '/orderMgmt/order',
          component: () => import('@/views/orderMgmt/order'),
          name: 'OrderMgmtOrder',
          meta: { title: '订单列表',  affix: true }
        },
        {
          id: 30010,
          path: '/orderMgmt/order/detail',
          component: () => import('@/views/orderMgmt/order/detail'),
          name: 'OrderMgmtOrderDetail',
          hidden:true,
          meta: { title: '订单详情',  affix: true }
        },
        {
          id: 30020,
          path: '/orderMgmt/refundOrder',
          component: () => import('@/views/orderMgmt/refundOrder'),
          name: 'OrderMgmtRefundOrder',
          meta: { title: '维权订单',  affix: true }
        },
        {
          id: 30020,
          path: '/orderMgmt/refundOrder/detail',
          component: () => import('@/views/orderMgmt/refundOrder/detail'),
          name: 'OrderMgmtRefundOrderDetail',
          hidden:true,
          meta: { title: '订单详情',  affix: true }
        },
      ]
    },
    {
      id: 100,
      path: '/member',
      name: 'member',
      component: Layout,
      meta: { title: '会员管理', icon: 'dashboard', affix: true },
      children: [
        {
          id: 10010,
          path: '/members',
          name: 'members',
          meta: { title: '会员列表',  affix: true },
          "component": () => import('@/views/members'),
        },
        {
          id: 10010,
          path: '/members/detail',
          name: 'membersDetail',
          meta: { title: '会员详情',  affix: true },
          "component": () => import('@/views/membersDetail'),
          hidden:true,
        },
        {
          id: 10030,
          path: '/membersRecharge',
          name: 'membersRecharge',
          meta: { title: '会员储值',  affix: true },
          "component": () => import('@/views/membersRecharge'),
        },
      ],
    },
    {
      id: 400,
      path: '/marketingMgmt',
      component: Layout,
      name: 'MarketingMgmt',
      meta: { title: '运营管理', icon: 'dashboard', affix: true },
      children: [
        {
          id: 40014,
          path: '/marketingMgmt/activeMgmt',
          component: () => import('@/views/marketingMgmt/activeMgmt'),
          name: 'MarketingMgmtActiveMgmt',
          meta: { title: '限时秒杀',  affix: true }
        },
        {
          id: 40015,
          path: '/marketingMgmt/pointList',
          component: () => import('@/views/marketingMgmt/pointList'),
          name: 'MarketingMgmtPointList',
          meta: { title: '积分商城',  affix: true }
        },
        {
          id: 40016,
          path: '/marketingMgmt/giftCardMgmt',
          component: () => import('@/views/marketingMgmt/giftCardMgmt'),
          name: 'MarketingMgmtGiftCardMgmt',
          meta: { title: '礼品卡列表',  affix: true }
        },
        {
          id: 40010,
          path: '/marketingMgmt/specialIndex',
          component: () => import('@/views/marketingMgmt/specialIndex'),
          name: 'MarketingMgmtSpecialIndex',
          meta: { title: '首页专题管理',  affix: true }
        },
        {
          id: 40011,
          path: '/marketingMgmt/banner',
          component: () => import('@/views/marketingMgmt/banner'),
          name: 'MarketingMgmtBanner',
          meta: { title: 'banner图管理',  affix: true }
        },
        {
          id: 40012,
          path: '/marketingMgmt/class',
          component: () => import('@/views/marketingMgmt/class'),
          name: 'MarketingMgmtClass',
          meta: { title: '金刚区管理',  affix: true }
        },
        {
          id: 40013,
          path: '/marketingMgmt/opinion',
          component: () => import('@/views/marketingMgmt/opinion'),
          name: 'MarketingMgmtOpinion',
          meta: { title: '意见管理',  affix: true }
        },
      ]
    },
    {
      id: 900,
      path: '/setting',
      component: Layout,
      name: 'setting',
      meta: { title: '设置', icon: 'dashboard', affix: true },
      children: [{
        id: 90010,
        path: '/setting/index',
        component: () => import('@/views/users/index'),
        name: 'SettingIndex',
        meta: { title: '账号管理', icon: 'dashboard', affix: true },
      }]
    }
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    }
    return { top: 0 }
  },
});

export default router;
